package com.lx.sync.core.executor;

import com.lx.sync.core.model.SyncBaseDTO;
import com.lx.sync.core.thread.AbstractBuildThreadPoolTemplate;
import com.lx.sync.core.thread.SyncRejectedExecutionHandler;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingDeque;

/**
 * 快速同步执行器
 *
 * @author machen
 * @date 2020/11/5 14:18
 */
@Slf4j
public class FastSyncExecutor extends BaseSyncExecutor {

    private final ExecutorService executorService = new AbstractBuildThreadPoolTemplate() {
        @Override
        public ThreadPoolInitParam initParam() {
            return new ThreadPoolInitParam("dataSyncExecutor", false)
                    .setCorePoolNum(Runtime.getRuntime().availableProcessors() << 1)
                    .setMaxPoolNum(Runtime.getRuntime().availableProcessors() << 3)
                    .setRejectedExecutionHandler(new SyncRejectedExecutionHandler())
                    .setKeepAliveTime(60000L)
                    .setWorkQueue(new LinkedBlockingDeque(1000));
        }
    }.buildFastPool();

    public FastSyncExecutor(AbstractSyncService abstractSyncService) {
        super(abstractSyncService);
    }

    @Override
    public void executor(List dataList) {

        executorService.submit(()->{
            super.executor(dataList);
        });

    }
}
